package com.qc.qx.services.impl;

import java.io.IOException;

import net.coobird.thumbnailator.Thumbnails;

import org.springframework.stereotype.Service;
import org.springframework.web.multipart.commons.CommonsMultipartFile;

import com.qc.qx.services.ThumbnailService;

@Service
public class ThumbnailServiceImpl implements ThumbnailService {

	public static final int WINDTH = 100;
	public static final int HEIGHT = 100;

	public String thumbnail(CommonsMultipartFile file, String uploadPath, String realUploadPath) {

		try {
			String des = realUploadPath + "/thum_" + file.getOriginalFilename();
			Thumbnails.of(file.getInputStream()).size(WINDTH, HEIGHT).toFile(des);
		} catch (IOException e) {
			e.printStackTrace();
		}
		return uploadPath + "/thum_" + file.getOriginalFilename();
	}
}
